<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />

</head>
<style>
    html,
    body {
        background-color: #fff;
        text-align: center;
    }

    .btn {
        width: 60%;
        margin: 2rem 20%;
        height: 2rem;
        line-height: 2rem;
        font-size: 0.8rem;
        background-color: #2780e8;
        color: #fff;
        border-radius: 10rem;
    }
</style>

<body>
    <div id="app">
        <img :src="'data:image/png;base64,' + imgUrl" alt="">

        <div class="btn" @click="save_img">保存图片</div>
    </div>
</body>

</html>
<script src="../script/set_root.js"></script>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/hb.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript">
    apiready = function () {
        hb_ready();
        get_ajax("doctor/card/qrcode", {
            userId: $api.getStorage("emp").userId
        }, function (res, err) {
            if (res.code == 2000 && res.data) {
                app.imgUrl = res.data.qrcode
            } else {
                toast("没有查询到哦")
            }
        })
    }
    //使用vue对数据进行绑定
    var app = new Vue({
        el: '#app',
        data: {
            imgUrl: "", // base64图片
        },
        methods: {
            save_img() {
                var trans = api.require('trans');
                trans.saveImage({
                    base64Str: app.imgUrl,
                    album: true,
                    imgPath: "fs://fuzhen_qrcode.png",
                    imgName: "fuzhen_qrcode.png"
                }, function (ret, err) {
                    if (ret.status) {
                        // alert(JSON.stringify(ret));
                        toast("保存成功")
                    } else {
                        // alert(JSON.stringify(err));
                        toast("保存失败")
                    }
                });
            }
        },
    })
</script>